//
//  ThriftRpcClient.swift
//  myThriftApp
//
//  Created by 沃灵宗 on 2020/3/15.
//  Copyright © 2020 沃灵宗. All rights reserved.
//
import UIKit
import Foundation
import Thrift


class ThriftRpcClient: NSObject {
     @objc func show() {
        print("hello bridge!");
        
            do {
                let serviceURL: URL = URL(string: "http://localhost:9090")!
                let session: URLSession = URLSession(configuration: .default)

                let transport: THTTPSessionTransport = THTTPSessionTransport.Factory(session: session, url: serviceURL).newTransport()
                //let transport = try TSocketTransport(hostname: "localhost", port: 9090)

                print("Transport established")

                //  var proto = TCompactProtocol(transport: transport)
                let proto = TBinaryProtocol(on: transport)
                //  var client = HermesClient(inoutProtocol: proto)
                let client = TestServiceClient(inoutProtocol: proto)
                print("1Transport established")
                let result = try client.Hello(HelloString: "Thrift!")
                  print("2Transport established")
                print(result)

                let sampleStruct = try client.GetSampleStruct(key: 3, value: "Three")
                print("\(sampleStruct.key) \(sampleStruct.value)")
                 print("3Transport established")

            } catch let error {
                 print("4Transport established")
                print("\(error)")
            }
        
    }
}
